#pragma once

#include <iostream>
#include "../httplib.h"
#include "../controller/request/add_contacts_request.pb.h"
#include "../controller/request/del_contacts_requext.pb.h"
#include "../controller/request/find_one_contacts_request.pb.h"
#include "../controller/response/add_contacts_response.pb.h"
#include "../controller/response/del_contacts_response.pb.h"
#include "../controller/response/find_all_contacts_response.pb.h"
#include "../controller/response/find_one_contacts_response.pb.h"
#include "../dao/ContactsMapper.h"
#include "../dao/contacts.pb.h"

using namespace httplib;

class ContactsServer
{
public:
    ContactsMapper contactsMapper;
public:
    //新增联系人
    void add(add_contact_req::AddContactsRequest& request,
    add_contact_resp::AddContactResponse* response) const;
    //删除联系人
    void del(del_contact_req::DelContactRequest& request,
    del_contact_resp::DelContactResponse* response) const;
    //查找联系人
    void find_one(find_one_contact_req::FindOneContactRequest& request,
    find_one_contact_resp::FindOneContactResponse* response) const;
    //显示所有联系人
    void find_all(find_all_contacts_resp::FindAllContactsResponse* response) const;

private:
    //打印日志
    void printAddContactRequest(add_contact_req::AddContactsRequest& request) const;

    //该函数对应的是void ContactsServer::add()函数中，添加联系人详细信息的具体操作
    void buildPeopleInfo(contacts::PeopleInfo* poople,
    add_contact_req::AddContactsRequest& request) const;

    //针对find_one函数中对于查找到联系人之后该联系人的详细信息的具体输出操作
    void buildFindOneContactResponse(const contacts::PeopleInfo& people,
    find_one_contact_resp::FindOneContactResponse* response) const;

    //对应void ContactsServer::printAddContactRequest()函数中打印所有联系人的具体信息
    void buildFindAllContactsResponse(contacts::Contacts& contacts,
    find_all_contacts_resp::FindAllContactsResponse* responce) const;
};